package com.tfswue.jqr.service;

import com.tfswue.jqr.apis.UserClinet;
import com.tfswue.jqr.entity.Order;
import com.tfswue.jqr.entity.User;
import com.tfswue.jqr.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private UserClinet userClinet;

//    public Order getOrderById(Integer id) {
//        Order order = orderMapper.selectById(id);
//        order.setUser(restTemplate.getForObject
//                ("http://localhost:8091/api/users/" + order.getUserId(), User.class));//发送请求，远程调用userService，获取用户信息
//        return order;
//    }

    //负载
    public Order getOrderById(Long id) {
        Order order = orderMapper.selectById(id);
        User user = userClinet.getUserById(order.getUserId());
        order.setUser(user);
//        order.setUser(restTemplate.getForObject
//                ("http://user-server/api/users/" + order.getUserId(), User.class));
        return order;
    }
}
